#!/usr/bin/env python
# -*- coding:utf-8 -*-
# projectname: pythoncode
# author: lzf time:2022/6/12
# name : 链表的反转

class Listnode(object):
    def __init__(self, val, next=None):
        if isinstance(val, int):
            self.val = val
            self.next = next
        elif isinstance(val, list):
            self.val = val[0]
            self.next = next
            head = self
            for i in range(1,len(val)):
                node = Listnode(val[i])
                head.next = node
                head = head.next
class Solution(object):
    def reverseList(self, head:Listnode):
        prev = None
        curr = head
        while curr != None:
            # 记录后一个节点
            tmp = curr.next
            # 改变节点的指向，反转链表
            curr.next = prev
            prev = curr
            # 继续处理后面的链表
            curr = tmp
        return prev
lst = [1,2,3,4,5]
list_node = Listnode(lst)
obj = Solution()
reve_list_node = obj.reverseList(list_node)
while reve_list_node:
    print(reve_list_node.val)
    reve_list_node = reve_list_node.next